import {NgModule} from '@angular/core';
import {Routes, RouterModule} from '@angular/router';
import {environment} from '@env/environment';

import {Constant} from '@core/constant';
import {TokenGuard} from '@core/auth/token/token.guard';

import {LayoutComponent} from '../layout/layout.component';
import {DashboardComponent} from './dashboard/dashboard.component';

const routes: Routes = [
  {
    path: '',
    redirectTo: '/' + Constant.MAIN_PATH + '/dashboard',
    pathMatch: 'full'
  },
  {
    path: 'passport',
    loadChildren: './passport/passport.module#PassportModule'
  },

  {
    path: Constant.MAIN_PATH,
    component: LayoutComponent,
    canActivate: [TokenGuard],
    children: [
      {path: '', redirectTo: 'dashboard', pathMatch: 'full'},
      {path: 'dashboard', component: DashboardComponent},
      {path: 'demo', loadChildren: './demo/demo.module#DemoModule'},
      {path: 'users', loadChildren: './users/user.module#UserModule'},
      {path: 'roles', loadChildren: './roles/role.module#RoleModule'},
      {path: 'menus', loadChildren: './menu/menu.module#MenuModule'},
      {path: 'question', loadChildren: './question/question.module#QuestionModule'},
      {path: 'knowledge', loadChildren: './knowledge/knowledge.module#KnowledgeModule'},
      {path: 'paper', loadChildren: './paper/paper.module#PaperModule'},
    ],
  }
];

@NgModule({
  imports: [
    RouterModule.forRoot(
      routes,
      {useHash: environment.useHash}
    )
  ],
  exports: [
    RouterModule
  ],
})
export class RouteRoutingModule {
}
